import QtQuick 1.0

Item {
    id: menu

    property bool cancelled: false
    property bool clickedNewGame

    PlaneHeader {
        id: planeAnim
        text: "WORD MASTER"
        height: 120

        onAnimationDone: {
            buttonAnim.start()
            if (menu.cancelled) {
                buttonAnim.complete();
            }
        }

        onDisappearDone: {
            disappearAnim.start()
        }
    }

    SequentialAnimation {
        id: buttonAnim
        running: false
        PropertyAnimation {
            duration: 500
            target: newGame
            property: "x"
            to: 20
        }

        PropertyAnimation {
            duration: 500
            target: howToPlay
            property: "x"
            to: 150
        }


        PropertyAnimation {
            duration: 500
            target: exit
            property: "x"
            to: 130
        }

        ScriptAction {
            script: {
               // planeContainer.animationDone();
            }
        }
    }

    SequentialAnimation {
        id: disappearAnim
        running: false
        PropertyAnimation {
            duration: 500
            target: newGame
            property: "x"
            to: 360
        }

        PropertyAnimation {
            duration: 500
            target: howToPlay
            property: "x"
            to: -howToPlay.width
        }

        PropertyAnimation {
            duration: 500
            target: exit
            property: "x"
            to: 360
        }

        ScriptAction {
            script: {
               if (clickedNewGame) {
                   // Start new game
                   baseScreen.wordMaster().init()
                   loader.source = "Game.qml"
               } else {
                   // Start demo mode
                   loader.source = "Demo.qml"
               }
            }
        }
    }

    Image {
        id: newGame
        x: -newGame.width
        y: 120
        z:1
        source: "assets/cloud1.png"
        Text {
            anchors.fill: parent
            font.pointSize: 12
            font.family: throwHands.name
            text: "New Game"
            horizontalAlignment: "AlignHCenter"
            verticalAlignment: "AlignVCenter"
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                clickedNewGame = true;
                disappearAnim.start()
            }
        }
    }

    Image {
        id: howToPlay
        x: parent.width
        y: 220
        z:1
        source: "assets/bigcloud.png"
        Text {
            anchors.fill: parent
            font.pointSize: 12
            font.family: throwHands.name
            text: "How to\nplay"
            horizontalAlignment: "AlignHCenter"
            verticalAlignment: "AlignVCenter"
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                clickedNewGame = false;
                disappearAnim.start()
            }
        }
    }

    Image {
        id: exit
        x: -exit.width
        y: 430
        z:1
        source: "assets/cloud1.png"
        Text {
            anchors.fill: parent
            font.pointSize: 12
            font.family: throwHands.name
            text: "Exit"
            horizontalAlignment: "AlignHCenter"
            verticalAlignment: "AlignVCenter"
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                Qt.quit();
            }
        }
    }

    Text {
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottomMargin: 20
        font.family: throwHands.name
        text: "\u00a9 2011  Douglas Hoskins"
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            menu.cancelled = true
            planeAnim.complete()
        }
    }
}
